package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ConsumptionBill;
import com.ruoyi.system.service.IConsumptionBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间消费账单Controller
 * 
 * @author txy
 * @date 2022-02-11
 */
@RestController
@RequestMapping("/system/consumption")
public class ConsumptionBillController extends BaseController
{
    @Autowired
    private IConsumptionBillService consumptionBillService;

    /**
     * 查询房间消费账单列表无分页
     */
    @PreAuthorize("@ss.hasPermi('system:consumption:list')")
    @GetMapping("/all")
    public AjaxResult listAll(ConsumptionBill consumptionBill)
    {
        String billId = consumptionBill.getBillId();
        List<ConsumptionBill> list = new ArrayList<>();
        if(billId != null && !"".equals(billId)){
            list = consumptionBillService.selectConsumptionBillList(consumptionBill);
        }
        return AjaxResult.success(list);
    }

    /**
     * 查询房间消费账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:consumption:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConsumptionBill consumptionBill)
    {
        startPage();
        List<ConsumptionBill> list = consumptionBillService.selectConsumptionBillList(consumptionBill);
        return getDataTable(list);
    }

    /**
     * 导出房间消费账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:consumption:export')")
    @Log(title = "房间消费账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsumptionBill consumptionBill)
    {
        List<ConsumptionBill> list = consumptionBillService.selectConsumptionBillList(consumptionBill);
        ExcelUtil<ConsumptionBill> util = new ExcelUtil<ConsumptionBill>(ConsumptionBill.class);
        util.exportExcel(response, list, "房间消费账单数据");
    }

    /**
     * 获取房间消费账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:consumption:query')")
    @GetMapping(value = "/{consumptionId}")
    public AjaxResult getInfo(@PathVariable("consumptionId") Long consumptionId)
    {
        return AjaxResult.success(consumptionBillService.selectConsumptionBillByConsumptionId(consumptionId));
    }

    /**
     * 新增房间消费账单
     */
    @PreAuthorize("@ss.hasPermi('system:consumption:add')")
    @Log(title = "房间消费账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsumptionBill consumptionBill)
    {
        return toAjax(consumptionBillService.insertConsumptionBill(consumptionBill));
    }

    /**
     * 修改房间消费账单
     */
    @PreAuthorize("@ss.hasPermi('system:consumption:edit')")
    @Log(title = "房间消费账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsumptionBill consumptionBill)
    {
        return toAjax(consumptionBillService.updateConsumptionBill(consumptionBill));
    }

    /**
     * 删除房间消费账单
     */
    @PreAuthorize("@ss.hasPermi('system:consumption:remove')")
    @Log(title = "房间消费账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{consumptionIds}")
    public AjaxResult remove(@PathVariable Long[] consumptionIds)
    {
        return toAjax(consumptionBillService.deleteConsumptionBillByConsumptionIds(consumptionIds));
    }
}
